package com.vision.service.impl;

import com.vision.common.bean.CommonResult;
import com.vision.common.bean.Pagination;
import com.vision.common.bean.msg91.Video91QueryOrder;
import com.vision.dao.msg91.Video91MsgDao;
import com.vision.entity.msg91.Video91Msg;
import com.vision.service.Msg91Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Filename Impl.java
 * @Description
 * @Version 1.0
 * @Author zhongc
 * @Email zhong_ch@foxmail.com
 * @History <li>Author: zhongc</li>
 * <li>Date: 2017/5/22</li>
 * <li>Version: 1.0</li>
 * <li>Content: create</li>
 */
@Service
public class Msg91ServiceImpl implements Msg91Service {

    private final static Logger LOGGER = LoggerFactory.getLogger(Msg91ServiceImpl.class);
    @Resource
    private Video91MsgDao video91MsgDao;

    @Override
    public CommonResult<Pagination<Video91Msg>> search91VideoMsg(Video91QueryOrder queryOrder) {
        CommonResult<Pagination<Video91Msg>> result = new CommonResult<>();
        try {
            int count = video91MsgDao.select91MsgByWordCount(queryOrder.getWord());
            int currPage = queryOrder.getCurrPage() <= 0 ? 0 : queryOrder.getCurrPage() - 1;
            queryOrder.setCurrPage(currPage * queryOrder.getPageSize());
            List<Video91Msg> video91MsgList = video91MsgDao.select91MsgByWord(queryOrder);
            result.setData(new Pagination<>(currPage, queryOrder.getPageSize(), count, video91MsgList));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setDesc("未知错误!");
            LOGGER.info("Msg91Service.search91VideoMsg error:{}", e);
        }
        return result;
    }
}
